//
//  String+CLExtension.swift
//  CLExtension
//
//  Created by CharlieLiao on 2017/7/27.
//  Copyright © 2017年 Charlie. All rights reserved.
//

extension Date
{
    public var timestamp: Int64 {
        Int64(timeIntervalSince1970*1000)
    }
    
    public var timestampStr: String {
        return "\(timestamp)"
    }
    
    public static var nowTimestampStr: String {
        return Date().timestampStr
    }
    
    public init?(timestamp: String) {
        guard let timestampD = TimeInterval(timestamp) else {
            return nil
        }
        self.init(timestamp: timestampD)
    }
    
    
    public init(timestamp: Int64) {
        self.init(timestamp: TimeInterval(timestamp))
    }
    
    public init(timestamp: TimeInterval) {
        self.init(timeIntervalSince1970: timestamp/1000)
    }
    
}
